package com.canbot.u05.glide;

import android.content.Context;
import android.support.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.Registry;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.module.AppGlideModule;

import java.io.InputStream;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

@GlideModule
public class GlideHttpModule extends AppGlideModule {

        public GlideHttpModule() {
                super();
        }

        @Override
        public boolean isManifestParsingEnabled() {
                return super.isManifestParsingEnabled();
        }

        @Override
        public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
                super.applyOptions(context, builder);
        }

        @Override
        public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
                OkHttpClient build = new OkHttpClient.Builder().writeTimeout(500, TimeUnit.SECONDS)
                                                               .connectTimeout(500, TimeUnit.SECONDS)
                                                               .readTimeout(500, TimeUnit.SECONDS)
                                                               .build();
                registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(build));
        }
}
